/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年2月21日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20200221_sorttest
 * @Desc
 * @author 52489
 * @date 2020年2月21日
 * @Version V1.0
 */
public class A20200221_sorttest {
    public static void main(String[] args) {
        int[] nums = { 10, 6, 3, 8, 33, 27, 66, 9, 7, 88, 20 };
        System.out.println(Arrays.toString(bubbo(nums)));
        // System.out.println(Arrays.toString(insert(nums)));
        // System.out.println(Arrays.toString(select(nums)));
    }

    /**
     * @param nums
     * @return
     */
    private static int[] select(int[] nums) {
        for (int i = nums.length - 1; i > 0; i--) {
            int maxIndx = 0;
            for (int j = 0; j < i + 1; j++) {
                if (nums[j] > nums[maxIndx]) {
                    maxIndx = j;
                }
            }
            int tmp = nums[maxIndx];
            nums[maxIndx] = nums[i];
            nums[i] = tmp;
        }
        return nums;
    }

    /**
     * @param nums
     * @return
     */
    private static int[] insert(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length - i + 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
        }
        return nums;
    }

    /**
     * @param nums
     * @return
     */
    private static int[] bubbo(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
        }
        return nums;
    }
}
